using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;

public class SkillCivilization : SkillBasic
{
    public bool isskilling;
    public bool skillchoosing;
    public float production;
    public float CD;
    public GameObject smartfish;
    public GameObject smartfish2;
    public GameObject tank;
    GameObject fashion;
    public float healthratio, damageratio;
    public bool wisper,capture;
    public bool rewards;
    bool newera;
    Transform playertransform;
    public bool[] technology=new bool[] {false,false,false,true};
    public bool[] product = new bool[] { false, false, false };
    public bool S100,S110, S211, S210, S201, S200;
    // Start is called before the first frame update
    void Start()
    {
        fashion = smartfish;
        isskilling = false;
        skillchoosing = false;
        wisper = false;
        capture = false;
        CivilizationCD.CDCurrent = 0;
        CivilizationCD.CD = 1;
        Debug.Log(technology.Length);
        technology[3] = true;
        if (S100 == true)
        {
            technology[3] = false;
        }
        if (S110 == true)
        {
            production += 5;
        }
        if (S201 == true)
        {
            for (int i = 0; i < 4; i++)
                technology[i] = true;
            rewards = true;
            healthratio += 0.5f;
            damageratio += 0.5f;
            capture = true;
        }
    }
    IEnumerator unit1end(float productionneed)
    {
        yield return new WaitForSeconds(productionneed/production);
        playertransform = GetComponentInParent<Transform>();
        Vector3 position = playertransform.position;
        position.y += 1f;
        Instantiate(smartfish, position, Quaternion.identity);
        if (S211 == true)
        {
            position.y += 0.2f;
            Instantiate(smartfish, position, Quaternion.identity);
        }
    }
    public void unit1(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(unit1end(productionneed));

    }
    IEnumerator unit2end(float productionneed)
    {
        yield return new WaitForSeconds(productionneed / production);
        playertransform = GetComponentInParent<Transform>();
        Vector3 position = playertransform.position;
        position.y += 1f;
        Instantiate(tank, position, Quaternion.identity);
        if (S211 == true)
        {
            position.y += 0.2f;
            Instantiate(tank, position, Quaternion.identity);
        }
    }
    public void unit2(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(unit2end(productionneed));

    }
    IEnumerator technology1end(float productionneed)
    {   
        
        technology[1-1] = true;

        yield return new WaitForSeconds(productionneed / production);
        capture = true;
        if (S200 == true)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(fashion, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void technology1(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(technology1end(productionneed));

    }
    IEnumerator technology1end_(float productionneed)
    {
        smartfish = smartfish2;
        technology[1 - 1] = true;

        yield return new WaitForSeconds(productionneed / production);
        if (S200 == true)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(fashion, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void technology1_(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(technology1end_(productionneed));

    }
    IEnumerator technology2end(float productionneed)
    {
        
        technology[2-1] = true;
        yield return new WaitForSeconds(productionneed / production);
        damageratio += 0.5f;
        if (S200 == true)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(fashion, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void technology2(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(technology2end(productionneed));
        
    }
    IEnumerator technology3end(float productionneed)
    {
        
        technology[3-1] = true;
        yield return new WaitForSeconds(productionneed / production);
        healthratio += 0.5f;
        if (S200 == true)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(fashion, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void technology3(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(technology3end(productionneed));

    }
    IEnumerator technology4end(float productionneed)
    {
        rewards = true;
        technology[4-1] = true;
        yield return new WaitForSeconds(productionneed / production);
        if (S200 == true)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(fashion, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void technology4(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(technology4end(productionneed));

    }
    IEnumerator technology4end_(float productionneed)
    {
        
        technology[4 - 1] = true;
        yield return new WaitForSeconds(productionneed / production);
        wisper = true;
        if (S200 == true)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(fashion, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void technology4_(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(technology4end_(productionneed));
    }
    IEnumerator production1end(float productionneed)
    {
        production += 10f;
        product[1-1] = true;
        yield return new WaitForSeconds(productionneed / production);
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void production1(float productionneed)
    {        
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(production1end(productionneed));

    }
    IEnumerator production2end(float productionneed)
    {   
        production *= 1.5f;
        product[2-1] = true;
        yield return new WaitForSeconds(productionneed / production);
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void production2(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(production2end(productionneed));
        
    }
    IEnumerator cultureend(float productionneed)
    {
        newera = true;
        fashion = tank;
        for (int i = 0; i < 4; i++)
            technology[i] = false;
        for (int i = 0; i < 2; i++)
            product[i] = false;
        yield return new WaitForSeconds(productionneed / production);
        if (rewards)
        {
            playertransform = GetComponentInParent<Transform>();
            Vector3 position = playertransform.position;
            position.y += 1f;
            Instantiate(smartfish, position, Quaternion.identity);
            Instantiate(tank, position, Quaternion.identity);
            position.y += 0.2f;
            Instantiate(smartfish, position, Quaternion.identity);
            position.y += 0.2f;
            Instantiate(smartfish, position, Quaternion.identity);
        }
        if (S210 == true)
        {
            production += 2f;
        }
    }
    public void culture(float productionneed)
    {
        CD = productionneed / production;
        CivilizationCD.CD = CD;
        StartCoroutine(cultureend(productionneed));

    }
    void Update()
    {
        if (CD > 0)
        {
            CD -= Time.deltaTime;
            CivilizationCD.CDCurrent = CD;
        }
        else if(skillchoosing==false){
            isskilling = false;
           // Debug.Log(isskilling);

        }
        if (Input.GetKeyDown(KeyCode)&&isskilling==false&&Time.timeScale>0)
        {

            isskilling = true;
            //Debug.Log(isskilling);
            if (newera)
            {
                GameRoot.Instance.scenesystem.scenestate.panelmanager.Push(new CivilizationPanel2());
                //TestGameRoot.Instance.scenesystem.scenestate.panelmanager.Push(new CivilizationPanel2());
            }
            else
            {
                GameRoot.Instance.scenesystem.scenestate.panelmanager.Push(new CivilizationPanel());
                //TestGameRoot.Instance.scenesystem.scenestate.panelmanager.Push(new CivilizationPanel());
            }
            
            //isskilling = true;
        }
    } 
}
